home *** CD-ROM | disk | FTP | other *** search
/ NeXT Enterprise Objects Framework 1.1 / NeXT Enterprise Objects Framework 1.1.iso / NextDeveloper / Examples / EnterpriseObjects / SQLExecutor / EOFDelegateAdaptorCategory.m < prev    next >
Encoding:
Text File  |  1994-12-31  |  6.5 KB  |  208 lines

  1. /*--------------------------------------------------------------------------
  2.  *
  3.  *     You may freely copy, distribute, and reuse the code in this example.
  4.  *     SHL Systemhouse disclaims any warranty of any kind, expressed or  
  5.  *    implied, as to its fitness for any particular use.
  6.  *
  7.  *
  8.  *      *
  9.  *     
  10.  *
  11.  *    Conforms To:    None
  12.  *
  13.  *    Declared In:    EOFDelegateAdaptorCategory.h
  14.  *
  15.  *  Courtesy of SHL Object Technology Center
  16.  *------------------------------------------------------------------------*/
  17.  
  18.  
  19. #import "EOFDelegateAdaptorCategory.h"
  20. #import "Evaluator.h"
  21.  
  22. @implementation EOFDelegateAdaptorCategory 
  23. /*--------------------------------------------------------------------------
  24.  *    EOAdaptor Delegate Methods
  25.  *------------------------------------------------------------------------*/
  26. - (BOOL)adaptor:(EOAdaptor *)adaptor willReportError:(NSString *)error
  27. {
  28.     // An adaptor sends this message to its delegate when an error has
  29.     // occurred.  If the delegate returns NO, the adaptor doesn't open an
  30.     // alert panel (or log the error to the console if it isn't in an
  31.     // application).
  32.     
  33.     BOOL    result = YES;
  34.     
  35.     [[[NXApp mainWindow] delegate] announce:adaptor 
  36.         selector:_cmd 
  37.         with:[NSArray arrayWithObject:error]];
  38.     
  39.         
  40.     return result;
  41. }
  42.  
  43.  
  44. /*--------------------------------------------------------------------------
  45.  *     EOAdaptorContext Delegate Methods
  46.  *
  47.  *     EOAdaptorContext sends messages to its delegate for any transaction
  48.  *     begin, commit, or rollback. The delegate can use these methods to
  49.  *     preempt these operations, modify their results, or simply track activity.
  50.  *
  51.  *     EODelegateResponse is used to indicate the result a delegate demands
  52.  *     on notification that a particular action will be taken.  If a delegate
  53.  *     returns EODelegateRejects, the sender of the delegation message must
  54.  *     abort the current operation and return a failure result.  If the
  55.  *     delegate returns EODelegateApproves, the sender may continue the
  56.  *     operation and return whatever result is appropriate.  If the delegate
  57.  *     returns EODelegateOverrides, the sender must do nothing, but return a
  58.  *     success result.  When a delegate overrides an operation it's
  59.  *     responsible for seeing that the result of that operation is performed
  60.  *     successfully.
  61.  *
  62.  *     typedef enum { 
  63.  *     EODelegateRejects, EODelegateApproves, EODelegateOverrides
  64.  *     } EODelegateResponse;
  65.  *
  66.  *------------------------------------------------------------------------*/
  67.  
  68. - (EODelegateResponse)adaptorContextWillBegin:context
  69. {
  70.     // Invoked from -beginTransaction to tell the delegate that
  71.     // a transaction is being started.
  72.     
  73.     int    result = EODelegateApproves;
  74.     
  75.     [[[NXApp mainWindow] delegate] announce:context selector:_cmd];
  76.     
  77.         
  78.     return result;
  79. }
  80.  
  81.  
  82. - (void)adaptorContextDidBegin:context
  83. {
  84.     // Invoked from -beginTransaction or -transactionDidBegin to tell the
  85.     // delegate that a transaction has begun. The delegate may take whatever
  86.     // action it needs based on this information.
  87.  
  88.     [[[NXApp mainWindow] delegate] announce:context selector:_cmd];
  89. }
  90.  
  91.  
  92. - (EODelegateResponse)adaptorContextWillCommit:context
  93. {
  94.     // Invoked from -commitTransaction to tell the delegate that
  95.     // a transaction is being committed.
  96.     
  97.     int    result = EODelegateApproves;
  98.     
  99.     [[[NXApp mainWindow] delegate] announce:context selector:_cmd];
  100.         
  101.     return result;
  102. }
  103.  
  104.  
  105. - (void)adaptorContextDidCommit:context
  106. {
  107.     // Invoked from -commitTransaction or -transactionDidCommit to tell the
  108.     // delegate that a transaction has been committed.  The delegate may take
  109.     // whatever action it needs based on this information.
  110.  
  111.     [[[NXApp mainWindow] delegate] announce:context selector:_cmd];
  112. }
  113.  
  114.  
  115. - (EODelegateResponse)adaptorContextWillRollback:context
  116. {
  117.     // Invoked from -rollbackTransaction to tell the delegate that
  118.     // a transaction is being started.
  119.     
  120.     int    result = EODelegateApproves;
  121.     
  122.     [[[NXApp mainWindow] delegate] announce:context selector:_cmd];
  123.     
  124.     return result;
  125. }
  126.  
  127.  
  128. - (void)adaptorContextDidRollback:context
  129. {
  130.     // Invoked from -rollbackTransaction or -transactionDidRollback to tell
  131.     // the delegate that a transaction has been rolled back.  The delegate may
  132.     // take whatever action it needs based on this information.
  133.  
  134.     [[[NXApp mainWindow] delegate] announce:context selector:_cmd];
  135. }
  136.  
  137.  
  138. /*--------------------------------------------------------------------------
  139.  *     EOAdaptorChannel Delegate Methods
  140.  *
  141.  *  EOAdaptorChannel sends messages to its delegate for nearly every
  142.  *  operation that would affect data in the database server. The delegate can
  143.  *  use these methods to preempt these operations, modify their results,
  144.  *  or simply track activity.
  145.  * 
  146.  *  IMPORTANT: read the comments for the EODelegateResponse type in
  147.  *  EOAdaptorContext.h for information on how the adaptor channel interprets
  148.  *  delegate responses.
  149.  *
  150.  *------------------------------------------------------------------------*/
  151.  
  152.  
  153. - (void)adaptorChannelDidChangeResultSet:channel
  154. {
  155.     // Invoked from -fetchAttributes:withZone: to tell the delegate that
  156.     // fetching will start for the next result set, when a select operation
  157.     // resulted in multiple result sets.  This method is invoked just after a
  158.     // -fetchAttributes:withZone: returns nil when there are still result sets
  159.     // left to fetch.
  160.  
  161.     [[[NXApp mainWindow] delegate] announce:channel selector:_cmd];
  162. }
  163.  
  164.  
  165. - (void)adaptorChannelDidFinishFetching:channel
  166. {
  167.     // Invoked from -fetchAttributes:withZone: to tell the delegate that
  168.     // fetching is finished for the current select operation.  This method is
  169.     // invoked when a fetch ends in -fetchAttributes:withZone: because there
  170.     // are no more result sets.
  171.  
  172.     [[[NXApp mainWindow] delegate] announce:channel selector:_cmd];
  173. }
  174.  
  175.  
  176. - (EODelegateResponse)adaptorChannel:channel 
  177.     willEvaluateExpression:(NSMutableString *)expression
  178. {
  179.     // Invoked from -evaluateExpression: to tell the delegate that an
  180.     // expression is about to be sent to the database server. The delegate
  181.     // may modify expression to affect the result.
  182.  
  183.     int    result = EODelegateApproves;
  184.  
  185.     [[[NXApp mainWindow] delegate] announce:channel 
  186.         selector:_cmd 
  187.         with:[NSArray arrayWithObject:expression]];
  188.  
  189.     return result;
  190. }
  191.  
  192.  
  193. - (void)adaptorChannel:channel
  194.     didEvaluateExpression:(NSString *)expression
  195. {
  196.     // Invoked from -evaluateExpression: to tell the delegate that a query
  197.     // language expression has been evaluated by the database server. The
  198.     // delegate may take whatever action it needs based on this information.
  199.  
  200.     [[[NXApp mainWindow] delegate] announce:channel 
  201.         selector:_cmd 
  202.         with:[NSArray arrayWithObject:expression]];
  203. }
  204.  
  205.  
  206. @end
  207.  
  208.